


export interface BaseResponse {
    msg: string
    code: number
}

export interface DataResponse<T> extends BaseResponse {
    data: T
}


export interface IKnowledgeSet {
    id?: number,
    isContentChanged?: boolean, //当前知识集是否发生变化 数量和每一条item的内容 title content
    isSelected?: boolean //当前的知识集是否被选中
    knowledgeSetId: string
    price: number
    title: string
    coverImage: string
    publicStates?: number // 使用枚举类型
    isFree?: boolean
    knowledgePoints: KnowledgePoint[]
    auditResult?: string
    kpCount?: number
    studyId?: number
    publisher?: number
    auditStates?: number
    userId?: number
    isBehind?: number
    userName?: string
    headImage?: string
    createTime?: string
    updateTime?: string
    needReviewCount?: number
    singleReviewCount?: number
    knowledgePointsCount?: number
    categoryId?: number
}


export class KnowledgeSet implements IKnowledgeSet {
    id: number = 0
    isContentChanged: boolean = false
    isSelected: boolean = false
    knowledgeSetId: string = ""
    price: number = 0
    title: string = ""
    coverImage: string = ""
    publicStates: number = 0
    isFree: boolean = true
    knowledgePoints: KnowledgePoint[] = []
    auditResult: string = ""
    kpCount: number = 0
    studyId: number = 0
    publisher: number = 0
    auditStates: number = 0
    userId: number = 0
    isBehind: number = 0
    userName: string = ""
    headImage: string = ""
    createTime: string = ""
    updateTime: string = ""
    needReviewCount: number = 0
    singleReviewCount: number = 0
    knowledgePointsCount: number = 0
    categoryId?: number = 1

    constructor(init?: Partial<KnowledgeSet>) {
        Object.assign(this, init)
    }
}


export class KnowledgePoint {
    isChanged: boolean = false
    isSelected: boolean = false
    knowledgePointId: string = generateUUID()
    title: string = ""
    content: string = ""
    knowledgeSetId: string = "" // 外键，保持与KnowledgeSet一致
    id: number = 0
    level: number = 0
    nextReviewTime: string = ""
    createTime: string = ""
    updateTime: string = ""
    studyId: number = 0
    version: number = 0
    deletedStatus?: number = 0
    cssType: number = 0
    memoryRate: number = 0

    constructor(init?: Partial<KnowledgePoint>) {
        Object.assign(this, init);
    }
}

export function generateUUID(): string {
    return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
        const r = (Math.random() * 16) | 0;
        const v = c === 'x' ? r : (r & 0x3) | 0x8;
        return v.toString(16);
    });
}
